{% extends "base.html" %}
{% load staticfiles %}

{% block title %}{{ title }}{% endblock %}


{% block content %}
    <!-- Main content -->
    <body>
    <section class="content-header">
{#        <h1 style="margin-bottom: 10px">持仓查询</h1>#}
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li class="active" style="margin-top:10px"><a href="#fa-check" onclick="tabs(0)" data-toggle="tab">持仓查询</a>
                </li>
            </ul>
            <div class="tab-content">
                <!--持仓查询-->
                <div class="tab-pane active" id="fa-check">
                    <div class="div-query">
                        <div class="lbl-query"><span>交易日</span>
                            <input class="input-query" type="text" id="Tradingday">
                            <span id="tradingdaySpanInfo" style="color: red;font-size: 14px;"></span>
                        </div>
                        <div class="lbl-query"><span>持仓帐号</span>
                            <input class="input-query" type="text" id="CombiNo">
                        </div>
                        <div class="lbl-query"><span>合约代码</span>
                            <input class="input-query" type="text" id="InstrumentID">
                        </div>
                        <div class="lbl-query"><span>持仓方向</span>
                            <select class="input-query" id="PosiDirection">
                                <option value=""></option>
                                <option value="1">净</option>
                                <option value="2">多头</option>
                                <option value="3">空头</option>
                            </select>
                        </div>
                        <div class="lbl-query">
                            <button class="btn-query" onclick="positionSearchSelect()">查询
                            </button>
                        </div>
                    </div>
                    <table class="stc-" id="PositionSearch">
                    </table>
                </div>
            </div>
        </div>
    </section>
    </body>

{% endblock %}

{% block scripts %}
    <script type="text/javascript">
        // 当前日期YYMMDD，并tradingday默认显示当天
        function GDate() {
            var myDate = new Date;
            var year = myDate.getFullYear(); //获取当前年
            var mon = myDate.getMonth() + 1; //获取当前月
            var date = myDate.getDate()
            if (mon < 10) {
                mon = "0" + mon
            }
            if (date < 10) {
                date = "0" + date
            }

            return year + mon + date
        }

        $('#Tradingday').val(GDate());

        //查询条件交易日绑定日期事件
        $("#Tradingday--不用控件了").datetimepicker({
            format: 'yyyymmdd',
            startView: 'year',
            maxView: 'year',
            minView: 'month',
            autoclose: true,
            pickerPosition: "bottom-right",
            language: 'zh',
            bootcssVer: 3, //显示箭头
        });

        //查询
        function positionSearchSelect() {
            var Tradingday = $("#Tradingday").val();
            var PosiDirection = $("#PosiDirection").val();
            var CombiNo = $("#CombiNo").val();
            var InstrumentID = $("#InstrumentID").val();
            //判断交易日是否为空，格式是否正确
            $('#tradingdaySpanInfo').text('');
            if (Tradingday.length !== 8) {
                console.log(Tradingday, Tradingday.length);
                $('#tradingdaySpanInfo').text('日期格式错误，日期格式为：yyyymmdd');
                return;
            }

            // 整理发送后台的数据
            var data = {
                "Tradingday": Tradingday,
                "PosiDirection": PosiDirection,
                "CombiNo": CombiNo,
                "InstrumentID": InstrumentID,
            };

            var JsonData = JSON.stringify(data);
            $.post("{% url 'Manager:position_list' %}", {"data": JsonData, 'positionSearch_select': 1}, function (r) {
                $("#PositionSearch").bootstrapTable("destroy").bootstrapTable({
                    height: 600,
                    columns: [
                        {
                            field: 'tradingday',
                            width: 80,
                            title: '交易日',
                        }, {
                            field: 'instrumentid',
                            width: 80,
                            title: '合约代码'
                        }, {
                            field: 'combino',
                            title: '持仓帐号',
                            width: 80,
                        }, {
                            field: 'exchangeid',
                            title: '交易所代码',
                            width: 60,
                        }, {
                            field: 'posidirection',
                            title: '持仓方向',
                            width: 60,
                        }, {
                            field: 'hedgeflag',
                            title: '投机套保',
                            width: 60,
                        }, {
                            field: 'position',
                            title: '持仓量',
                            width: 60,
                        }, {
                            field: 'ydposition',
                            title: '昨持仓',
                            width: 60,
                        }, {
                            field: 'frozenposition',
                            title: '冻结持仓',
                            width: 60,
                        }
                    ],
                    data: r,
                    // height: 600,
                    // width: 100,
                    //******前端分页设置****
                    pagination: true,
                    pageNumber: 1,
                    pageSize: 20,
                    pageList: [10, 20, 50, 100],
                    paginationHAlign: "right",
                    paginationDetailHAlign: "left"
                    //******前端分页设置****
                });
            });

        }

        //bstable渲染页面（固定写法）
        function InitBootstrapTable(my_url, my_table_id, my_columns, my_filename, tab_type, req_type) {
            $('#' + my_table_id).bootstrapTable('destroy').bootstrapTable({
                url: my_url,
                method: 'get',
                columns: my_columns,
                toolbar: '#toolbar',
                striped: true,
                cache: false,
                pagination: true,
                sortable: true,
                height: 600,
                sortOrder: "asc",
                queryParams: function (pageRequest) {
                    pageRequest['tab_type'] = tab_type;
                    pageRequest['req_type'] = req_type;
                    return pageRequest;
                },
                sidePagination: "server",
                pageNumber: 1,
                pageSize: 20,
                pageList: [10, 25, 50, 100],
                {#search: true,#}
                {#            strictSearch: false,#}
                {#    showColumns: true,      #}
                {#            showRefresh: true,      #}
                minimumCountColumns: 2,
                clickToSelect: true,
                uniqueId: "_id",
                {#    showToggle: true,    #}
                cardView: false,
                detailView: false,
                {#    showExport: true,#}
                buttonsAlign: "right",
                {#exportDataType: "all",#}
                {#            exportTypes: ['excel'],#}
                {#            Icons: 'glyphicon-export',#}
                {#            exportOptions: {#}
                {#              fileName: my_filename,#}
                {#            },#}
            })
        }

        // 报单查询
        my_columns = [
            {
                checkbox: true,
                visible: false
            },
            {
                field: 'Tradingday',
                width: 80,
                title: '交易日',
            }, {
                field: 'InstrumentID',
                width: 80,
                title: '合约代码'
            }, {
                field: 'CombiNo',
                title: '持仓帐号',
                width: 80,
            }, {
                field: 'ExchangeID',
                title: '交易所代码',
                width: 60,
            }, {
                field: 'PosiDirection',
                title: '持仓方向',
                width: 60,
            }, {
                field: 'HedgeFlag',
                title: '投机套保',
                width: 60,
            }, {
                field: 'Position',
                title: '持仓量',
                width: 60,
            }, {
                field: 'YdPosition',
                title: '昨持仓',
                width: 60,
            }, {
                field: 'FrozenPositon',
                title: '冻结持仓',
                width: 60,
            }
        ];

        //渲染table数据
        InitBootstrapTable("{{url}}", "PositionSearch", my_columns, "PositionTableFileName", '0', "1");
    </script>

{% endblock %}